<?php

namespace App\Tables;

use Illuminate\Database\Eloquent\Model;

class ChargeOrder extends Model
{
    protected $dates = ['paid_at'];

    protected $appends = [
        'status_text',
        'pay_mode_text'
    ];

    /**
     * 生成充值订单编号
     * @return string
     */
    public function makeOrderSn()
    {
        return strtoupper(uniqid(date('ymdHi')));
    }


    /**
     * 获取订单状态文字
     * @return mixed|string
     */
    public function getStatusTextAttribute()
    {
        switch ($this->status) {
            case 'wait_pay':
                return '未支付';
            case 'paid':
                return '已支付';
            default:
                return $this->status;

        }
    }

    /**
     * 获取支付方式文字
     * @return mixed|string
     */
    public function getPayModeTextAttribute()
    {
        switch ($this->pay_mode) {
            case 'alipay':
                return '支付宝';
            case 'wxpay':
                return '微信支付';
            default:
                return $this->pay_mode;
        }
    }
}
